//该文件创建store
import Vuex from 'vuex'
//引入vue
import Vue from 'vue'
Vue.use(Vuex)
//actions
const actions={
    jia(context,value){
        context.commit('JIA', value)
    },
    jian(context,value){
        context.commit('JIAN',value)
    },
    jiaOdd(context,value){
        if(context.state.sum % 2){
            context.commit('JIA', value)
        }
    },
    jiaWait(context,value){
        setTimeout(() => {
            context.commit('JIA', value)
        }, 300);
    }
}
//mutations
const mutations={
    JIA(state,value){
        state.sum += value
    },
    JIAN(state,value){
        state.sum -= value
    }
}
//state
const state={
    sum:0
}
export default new Vuex.Store({
    actions,
    mutations,
    state
})